<?php

class asynchronous_Object_Date {
	
	protected $_timestamp;


	//Matching of the unit with the equivalent to input in PHP date function
	//http://fr.php.net/manual/en/function.date.php
	static protected $_unitTimeDateFunctionMatching = array('minute' => 'i' ,'hour' => 'G','day' => 'j','weekday' => 'N','month' => 'n','year' => 'Y');	
	
	public function __construct($timestamp) {
		$this->_timestamp = $timestamp; 
		$this->reset('second');
	}
	public function getMinute() {
		return (int) date(self::$_unitTimeDateFunctionMatching['minute'],$this->_timestamp);			
	}
	public function getHour() {
		return (int) date(self::$_unitTimeDateFunctionMatching['hour'],$this->_timestamp);			
	}
	public function getDay() {
		return (int) date(self::$_unitTimeDateFunctionMatching['day'],$this->_timestamp);			
	}
	public function getWeekday() {
		return (int) date(self::$_unitTimeDateFunctionMatching['weekday'],$this->_timestamp);			
	}
	public function getMonth() {
		return (int) date(self::$_unitTimeDateFunctionMatching['month'],$this->_timestamp);			
	}
	public function getYear() {
		return (int) date(self::$_unitTimeDateFunctionMatching['year'],$this->_timestamp);			
	}	
	
	public function getTimestamp() {
		return $this->_timestamp;	
	}
			
	public function reset($unit) {
			switch ($unit) {
		    case 'second':
		        $this->_timestamp = mktime  ($this->getHour(),  $this->getMinute(),  0,  $this->getMonth(),  $this->getDay(),  $this->getYear());
		        break;
		    case 'minute':
		        $this->_timestamp = mktime  ($this->getHour(),  0,  0,  $this->getMonth(),  $this->getDay(),  $this->getYear());
		        break;
		    case 'hour':
		        $this->_timestamp = mktime  (0,  0,  0,  $this->getMonth(),  $this->getDay(),  $this->getYear());
		        break;
		    case 'day':
		        $this->_timestamp = mktime  (0,  0,  0,  $this->getMonth(),  1,  $this->getYear());
		        break;
		}	
	}
	
	public function modify($how) { 
		$this->_timestamp = strtotime($how, $this->_timestamp); 
		return;
	}

	
}	
	